'''
=====使用QDialog显示通用对话框

使用 QDialog显示通用对话框
基类 QDialog，在此基础上有扩展了4个
QMessageBox 消息对话框
QColorDialog 颜色对话框
QFontDialog 字体对话框
QInputDialog 获取用户输入信息的对话框
窗口
QMainWindow
QWidget
QDialog  没有菜单
'''
# 主窗口中点击按钮显示对话框
import sys

from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *


class QDialogDemo(QMainWindow):
    def __init__(self):
        super(QDialogDemo, self).__init__()
        self.initUI()

    def initUI(self):
        self.setWindowTitle("QDialog案例")
        self.resize(300, 200)
        # 常见button
        self.button = QPushButton(self)
        self.button.setText("弹出对话框")
        self.button.move(50, 50)
        self.button.clicked.connect(self.showDialog)

    def showDialog(self):
        dialog = QDialog()
        button = QPushButton("确定", dialog)
        button.clicked.connect(dialog.close)
        button.move(50, 50)
        dialog.setWindowTitle("对话框")
        dialog.setWindowModality(Qt.ApplicationModal)  # 设置模式

        dialog.exec()  # 显示对话框


if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setWindowIcon(QIcon('./img/juice.png'))
    main = QDialogDemo()
    main.show()
    sys.exit(app.exec_())
